using System.Collections.Generic;
using System.Net;

namespace Kannon.Core
{
    internal class KannonApplicationHandler : IKannonHandler
    {
        private readonly IList<RouteHandlerDescriptor> routeHandlers;

        public KannonApplicationHandler(IList<RouteHandlerDescriptor> routeHandlers)
        {
            this.routeHandlers = routeHandlers;
        }

        public KannonResponse Handle(KannonRequest request)
        {
            foreach(var routeHandler in routeHandlers)
            {
                if(request.Url.AbsolutePath.ToLowerInvariant().CompareTo(routeHandler.Url) == 0)
                    return routeHandler.Handler(request);
            } // foreach

            return HttpStatusCode.NotFound;
        }
    }
}